<?php
/*
* komplette taxonomy einlesen
*/
$this->import('Database');
$taxLabels = $this->Database->prepare("select * from tl_taxonomy")
                            ->execute();
while($taxLabels->next())
{
    $taxLabelssum[$taxLabels->id] = array
    (
    'name'           => $taxLabels->name,
    'name_en'        => $taxLabels->name_en,
    'alias'          => $taxLabels->alias,
    'pid'            => $taxLabels->pid,
    'tennzeichen'    =>$taxLabels->trennzeichen,
    );
}

/*
*  taxonomy labelgenerator
*/
function getTaxLabel($taxid,$taxArray)
{
    if($GLOBALS['TL_LANGUAGE'] != 'de')
    {
        $taxLabel = $taxArray[$taxid]['name_'.$GLOBALS['TL_LANGUAGE'].''];
    }
    else
    {
        $taxLabel = $taxArray[$taxid]['name'];
    }
    return $taxLabel;
}
/*Parent Name for headlines*/
function getParentName($taxid,$taxArray)
{
    $id = $taxid[1]['id'];
    $pid = $taxArray[$id]['pid'];
    return getTaxLabel($pid,$taxArray);
   // print_r ($taxid[1]['id']);
}

/*
 *
*  generate filterlink
*/
function getFilterLink($link,$alias)
{
    //generate url for detail page
    if($GLOBALS['TL_LANGUAGE'] != 'de')
    {
        $urlArray = explode('/',$link);
        if(count($urlArray) <= 7 )
        {
            $urlArray[6] = $alias.".html";
        }
        else
        {
            $urlArray[6] = $alias;
        }
        $filterurl = implode('/',$urlArray);
    }
    else
    {
        $filterurl = $link;
    }
    return $filterurl;
}

?>

<?php if ($this->filterOptions): ?>
<div class="filter_group">

<?php if ($this->filter_headline): ?>
<<?php echo $this->filter_hl; ?>><?php echo $this->filter_headline; ?></<?php echo $this->filter_hl; ?>>
<?php endif; ?>

<?php foreach($this->widgets['filter'] as $filteritem): ?>
    <!-- select -->
    <div class="widget <?php echo $filteritem['id']; ?>">
        <label for="ctrl_<?php echo $filteritem['id']; ?>"><?php echo getParentName(deserialize($filteritem['options']),$taxLabelssum) ?></label>
        <br />
        <select
            class="<?php echo ($filteritem['multiple'] ? 'multiselect' : 'select'); ?>"
            id="ctrl_<?php echo $filteritem['id']; ?>"
            name="<?php echo ($filteritem['multiple'] ? $filteritem['name'].'[]' : $filteritem['name']); ?>"
            onchange="window.location=this.value">
            <?php $i = 0; foreach(deserialize($filteritem['options']) as $filterOption): ?>
                <option <?php if ($filterOption['selected']) echo 'selected="selected" '; ?>
                    value="<?php echo getFilterLink($filterOption['value'],$objPage->alias); ?>">
                    <?php echo ($filterOption['id']) ? getTaxLabel($filterOption['id'],$taxLabelssum) :  $filterOption['label'];?>
                </option>
            <?php $i++; endforeach; ?>
        </select>
        <? //print_r($filterOption); ?>
    </div>
<?php endforeach; ?>
</div>
<?php endif; ?>



<!--
<div class="clearall">
<a href="<?php echo $this->clearall; ?>" title="<?php echo $this->clearallText; ?>"><?php echo $this->clearallText; ?></a>
</div>
-->
<?
/*
 * tamplate variablen
 */
//$this->showTemplateVars();
?>

<!-- radio
    <div class="widget <?php echo $filteritem['id']; ?>">
        <label for="ctrl_<?php echo $filteritem['id']; ?>"><?php echo $filteritem['label']; ?></label>
        <?php if (($filteritem['inputType'] == 'radio') || ($filteritem['inputType'] == 'checkbox')): ?>

        <div id="ctrl_<?php echo $filteritem['id']; ?>" class="radio_container">
            <?php foreach(deserialize($filteritem['options']) as $filterOption): ?>
            <span>
                <input id="opt_<?php echo $filteritem['id']; ?>_<?php echo $filterOption['id']; ?>"
                    <?php echo $filteritem['attributes']; ?>
                    <?php if ($filterOption['selected']) echo ' checked="checked" '; ?>
                    <?php echo ($filteritem['multiple'] ? 'class="checkbox" type="checkbox"' : 'class="radio" type="radio"'); ?>
                    name="<?php echo ($filteritem['multiple'] ? $filteritem['name'].'[]' : $filteritem['name']); ?>"
                    value="<?php echo getFilterLink($filterOption['value'],$objPage->alias); ?>"
                    onclick="window.location=this.value"
                />
                <label for="opt_<?php echo $filteritem['id']; ?>_<?php echo $filterOption['id']; ?>">
                    <?php echo ($filterOption['id']) ? getTaxLabel($filterOption['id'],$taxLabelssum) :  $filterOption['label'];?>
                </label>
                <br/>
            </span>
            <?php endforeach; ?>
        </div>
        <?php endif; ?>

    </div>
    -->

